<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <form action="">
    用户名：<input type="text" name="username" id="uname"><br>
    密  码：<input type="text" name="userpwd" id="upwd"><br>
    <input type="button" id="btn" value="提交">
  </form>
  <script>
    //1.获取按钮注册点击事件
    document.getElementById('btn').onclick = function(){
      //2.通过DOM方式获取 用户名和密码
      var uname = document.getElementById('uname').value;
      var upwd = document.getElementById('upwd').value;
      //3.发送Ajax请求并将 用户名和密码一起发送给后端
      var xhr = new XMLHttpRequest();
      xhr.open('get','/api/getForm?uname='+uname+'&upwd='+upwd);
      xhr.send();
      xhr.onload = function(){
        alert(xhr.responseText);
      };
    };
  </script>
</body>
</html> 